$(document).ready(function () {

    var userId = $('#userId').val();
    $(".face_upload").each(function () {

         var  this_ = $(this);

         // 获取选择图片的盒子
         var upload_btn =    this_.find(".upload_btn");
         var  upload_btn_id =  upload_btn.attr("id");

         // 获取装图片的盒子
         var upload_img =    this_.find(".upload_img");
         var  upload_img_id =  upload_img.attr("id");

         // 获取keyName值
         var keyName = this_.find('.file_input_value');
         var keyName_val = keyName.attr('keyName');

        var img_value = this_.find('.file_input_value').val();
        if (img_value != null && img_value != "" && img_value != undefined) {
            var img_url = "/applyment/getFile?fielId=" + img_value;
            var img = this_.find(".upload_img img");
            img.attr('src', img_url);//图片链接（base64
        }
        $.fileUpload({
            filebutton: "#"+upload_btn_id,
            previewZoom: "#"+upload_img_id,
            keyName_val: keyName_val,
            httpUrl: "/applyment/fileUpload",
            userId: userId
        });

    });

    // 经营目录开始
    // 搜索页面
    $(document).on('click','.open-search', function () {
        $.popup('.popup-search');
    });

    // 将搜索值返回
    $('.leiMu_content').html($('.category_query').val());
    $(document).on('click','.close-popup', function () {
        $('.leiMu_content').html($('.category_query').val());
    });
    // 类目数组
    var categoryArr = ["文具及办公用品","鞋帽清洗","歌舞厅/夜店","网络电话、传真","其他专业服务","建筑材料承包商","办公及商务家具（批发商）","出版印刷服务","汽车维修、洗车保养、美容装饰","物流、快递","物流货运服务","金融机构-商业银行服务","金融机构-其他服务","金融机构-自动现金服务","演出票务服务","丧仪殡葬服务","其他会员组织","景观美化与园艺服务","电信运营商","计算机维护和修理服务","活动房车销售商","乐队和文艺表演","话费充值与缴费","信息检索服务（信息平台）","门户网站","网络论坛","软件系统商","家具维修、翻新","拖车服务","成人用品/避孕用品/情趣内衣","机票平台","航空系统商","报纸、杂志","运动和娱乐露营","油漆、清漆用品（批发商）","制服与商务正装定制","活动房车场及野营场所","游泳、SPA、洗浴设备","鞋类销售平台（批发商）","航空公司","档案","机票代理人","测试实验服务","自行车及配件","体育用品/器材","书、期刊和报纸（批发商）","美甲","美容/美发服务","站内清算","手表、钟表和首饰维修店","花木栽种用品、苗木和花卉（批发商）","宠物及宠物用品","药物","典当行","文具、办公用品、复印纸和书写纸（批发商）","农业合作与农具","电器承包商","花店","办公电器和小家电维修","机动车供应及零配件（批发商）","化妆品","电器维修","空调、制冷设备维修","杂货店","数码产品及配件","其他医疗保健服务","家政服务","商用计算机及服务器","广告服务","按摩服务","服装出租","肉、禽、蛋及水产品","水果店","美容SPA和美体保健","会员制批量零售店","家用电器","贵金属投资","不动产代理-房地产经纪","外币汇兑","国外代购及免税店","海上船只遇难救助","打字设备、打印复印机、扫描仪","乐器","团购及折扣店","邮票/纪念币","宗教物品","游轮及巡游航线服务","其他自助","行李箱包","工艺美术用品","艺术品和画廊","其他工程承包商","机动车综合经营","雪车","国家邮政","自助零售","平台类综合商城","自助服务","自助娱乐","露营及旅行汽车","自助借还","婚介服务","男性服饰","未列入其他代码的商用器材","金属产品承包商","商业摄影、设计、绘图服务","导购、经纪和拍卖服务","办公、影印及微缩摄影器材（批发商）","会计、审计、财务服务","婚庆服务","电子档案","财务债务咨询","校园团餐","专业摄影器材","复印及绘图服务","钟表店","综合团餐","文字处理/翻译速记","古玩复制品（赝品）","医学及牙科实验室","房车和娱乐车辆出租","汽车出租","卡车及拖车出租","大型仓储式家庭用品卖场","瓷器、玻璃和水晶摆件","混凝土承包商","慈善和社会公益服务","征信和信用报告咨询服务","债务催收机构","烟草/雪茄","不动产管理－物业管理","计算机软件","超市（非平台类）","刻版排版服务","摩托车及配件","礼品、卡片、纪念品","停车服务","少年宫及青少年发展中心","其他学校和教育服务","木材与建材商店","游乐园、马戏团、嘉年华","配饰商店","健身和运动俱乐部","法律咨询和律师事务所","动物园、水族馆","其他娱乐服务","高尔夫球场","护理和照料服务","电玩娱乐场所","医疗器械","建筑、工程和测量服务","茶叶","装修、装潢、园艺","保健品","运输搬运设备、起重装卸设备","飞机及配件、航道设施","轨道交通设备器材","面包糕点","烟花爆竹","油品燃料经销","拖车、篷车及娱乐用车","棋牌室","展览和艺术场馆","大学与学院","旧商品店、二手商品店","女性成衣","助听器","民营医院","康复和身体辅助用品","公立医院","文物古董","付费电视","手机图铃","在线文学类","大型旅游景点","休闲游戏","运动服饰","灭虫及消毒服务","商户拓展","出租船只","彩票","帐篷和遮阳篷商店","乳制品/冷饮","清洁、保养及门卫服务","船舶及配件销售","视频点播","其他在线应用或综合类","儿童保育服务（含学前教育）","房地产开发商","书籍","个人资金借贷","其他专业零售店","公共事业-自来水缴费","公共事业-清洁服务缴费","玻璃、油漆涂料、墙纸","公共事业-电力缴费","公共事业-煤气缴费","玩具、游戏用品","图书馆","正骨医生","旅行社和旅游服务","行业协会和专业社团","国际货运代理和报关行","公共事业（电、气、水）","加油站、服务站","糖果及坚果商店","手机、通讯设备销售","职业技能培训","商业保理公司","函授学校（成人教育）","金属产品和服务（批发商）","商业和文秘学校","内衣/家居服","眼镜店","直销","P2P","借贷消费平台","直销代理","化工产品","电话外呼直销","按摩医生","电话接入直销","眼科医疗服务","订阅订购服务","机场服务","旅游相关服务直销","上门直销（直销员）","目录直销平台","猎头、职业中介","手足病医疗服务","保险直销（代扣）","汽车零配件","网游运营商（含网页游戏）","网游周边服务、交易平台","消费金融公司","小贷公司","融资租赁公司","汽车金融公司","网络游戏点卡、渠道代理","信托公司","金融租赁公司","游戏系统商","融资担保公司","支付机构","度假用别墅服务","电影院及电影票","社区医疗服务机构、诊所等","证券期货基金","管道及供暖设备","住宿服务（旅馆、酒店、汽车旅馆、度假村等）","出租车服务（TAXI）","路桥通行费","其他工业原料和消耗品","母婴用品","宗教组织","设备、工具、家具和电器出租","未列入其他代码的运输服务","商业摄影摄像服务","药品、药品经营者（批发商）","公关和企业管理服务","洗熨服务（自助洗衣服务）","保安和监控服务","洗衣服务","急救服务","室内清洁服务","各类维修相关服务","干洗店","五金器材及用品（批发商）","家用五金工具","音像制品","布料、缝纫用品和其他纺织品（批发商）","焊接维修服务","电气产品和设备","牙科医生","长途公路客运","酒吧、舞厅、夜总会","GCAS紧急服务（仅限Visa使用）","铁路货运","快餐店","咖啡厅、茶馆","音像制品出租","宴会提供商","餐厅、订餐服务","Visa信任服务","家用纺织品","兽医服务","葡萄酒生产商","其他食品零售","家用电子游戏","其他酒类生产商","电汇和汇票服务","摄影服务","汽车、二手车销售","男士用品：剃须刀、烟酒具、瑞士军刀","其他综合零售","鞋类","草坪和花园用品","其他工业耐用品","裁缝、修补、改衣制衣","假发等饰品","桌球/桌游","各类服装及饰物","保龄球","未列入其他代码的建材（批发商）","窗帘、帷幕、室内装潢","家具/家庭摆设","酒类","地板和地毯","壁炉、屏风","各种家庭装饰专营","船舶、海运服务提供商","SNS社交网站","网站设计、推广","清洁抛光服务","高档时装及奢侈品","互联网IDC服务","体育场馆","保险公司","工业设备和制成品","保险代理","珠宝和金银饰品","艺术创作服务","公共交通","汽车协会","铁路客运","皮草皮具","中小学校"];

    // 没有值全部显示数据
    for (var i = 0; i < categoryArr.length; i++) {
        var text = categoryArr[i];
        $(".category_ul").append("<li class='category-li close-popup'>" + text + "</li>");
    }
    // 将选中的li值给input
    $(".category-li").click(function () {
        var val = $(this).text();
        $(".category_query").val(val);
        $('.leiMu_content').html($('.category_query').val());
    });
    // 监听input值变化
    $('.category_query').on('keyup',function () {

        var category_ul = $('.category_ul');//查询框ul
        var input_val = $(this).val();//搜索值
        if (input_val){
            category_ul.empty();//清空ul元素内容
            var a = [];//放符合搜索数值的数组
            //有值把符合条件的值放入一个声明的变量
            for (var i = 0; i < categoryArr.length; i++) {
                var text = categoryArr[i];
                var indexof = text.indexOf(input_val);
                if (indexof > -1) {
                    a.push(text);
                }
            }
            //循环显示符合条件的值
            for (var i = 0; i < a.length; i++) {
                var text = a[i];
                category_ul.append("<li class='category-li close-popup'>" + text + "</li>");
            }
            $(".category-li").click(function () {
                var val = $(this).text();
                $(".category_query").val(val);
                $('.leiMu_content').html($('.category_query').val());
            })
        }else {
            //没有值全部显示数据
            category_ul.empty();
            for (var i = 0; i < categoryArr.length; i++) {
                var text = categoryArr[i];
                category_ul.append("<li class='category-li close-popup'>" + text + "</li>");
            }
            $(".category-li").click(function () {
                var val = $(this).text();
                console.log(val);
                $(".category_query").val(val);
                $('.leiMu_content').html($('.category_query').val());
            })
        }

    });
    // 经营目录结束


    // 点击保存开始
    $('.zfb_form_but').on('click',function () {
        var formData = $('form').serializeArray();
        var name = $('input[name=name]').val();
        var email = $('input[name=email]').val();
        var mobile = $('input[name=mobile]').val();
        var alipayAccount = $('input[name=alipayAccount]').val();
        var aliFinalRate = $('input[name=aliFinalRate]').val();
        var business_license = $('#bl_img img').attr('src');
        var store_pic = $('#sp_img img').attr('src');
        var business_category = $('input[name=business_category]').val();
        if(!name){
            $.toast("名字必填");
        }else if(!email){
            $.toast("邮箱必填");
        }else if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))){
            $.toast("电话号码有误");
        }else if(!alipayAccount){
            $.toast("支付宝账号必填");
        }else if(aliFinalRate<0.2 || aliFinalRate>0.6){
            $.toast("结算费率必填");
        }else if(!business_category){
            $.toast("经营类目必填");
        }else if(!business_license){
            $.toast("营业执照必传");
        }else if(!store_pic){
            $.toast("店铺招牌照片必传");
        }else  {
            $.post('/alimchinfo/edit',formData,function (result) {
                if(result.code==1){
                    $.toast("保存成功");
                }else{
                    $.toast(result.message);
                }
            });
        }
    });
    // 点击保存结束

});
